package com.edu.interceptor;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class MyInterceptor implements MethodInterceptor {

    private Object obj ;

    public MyInterceptor(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        long start = System.currentTimeMillis();
        Object result  =  method.invoke(obj,objects);
        long end = System.currentTimeMillis();
        System.out.println(obj.getClass()+":"+method.getName()+"执行耗时"+(end - start));
        return result;
    }
}
